<?php

/*
  8/12/2009: Immanuel add image_id, file_id, create_date field
  Sep 12, 2011 - Add agregate
				 Remove background property
				 
*/

class article {
	function form($object) {
		if (!defined("SYS_FORMS")) require_once(BASE."subsystems/forms.php");
		exponent_forms_initialize();
		
		$form = new form();
		if (!isset($object->id)) {
			$object->title = "";
			$object->body = "";
			$object->image_id=0;
			//$object->background_id=0;
			$object->file_id=0;
			$object->ower_id=1;
			$object->create_date=time();
			// sep 13, 2011 - trungdt - add summary
			$object->summary='';
			$object->dont_show_readmore=0;
		} else {
			$form->meta("id",$object->id);
		}
		
		$form->register("title","Article Title",new textcontrol($object->title,50,false,200));
		$form->register("summary","Summary",new texteditorcontrol($object->summary,5,60,true));
		$form->register("body","Article Body",new htmleditorcontrol($object->body));
		$form->register('create_date',"Create date",new yuidatetimecontrol($object->create_date,"", true, true, false));
		$form->register('file_id','Article file', new ajax_select_file('file_id',0,$object->file_id,true));
		$form->register('image_id','Image', new ajax_select_file('image_id',0,$object->image_id,false));
		$form->register('dont_show_readmore','Dont show Readmore button',new checkboxcontrol($object->dont_show_readmore,true));
		//$form->register('background_id','Background', new ajax_select_file('background_id',0,$object->background_id,false));
		$form->register("submit","",new buttongroupcontrol("Save","","Cancel"));
		
		exponent_forms_cleanup();
		return $form;
	}
	
	function update($values,$object) {
		$object->title = $values['title'];
		$object->body = $values['body'];
		$object->image_id = $values['image_id'];
		//$object->background_id = $values['background_id'];		
		$object->file_id = $values['file_id'];
		$object->create_date = yuidatetimecontrol::parseData('create_date',$values);
		if ($object->create_date ==0)
			$object->create_date = time();
		
		// Sep 12, 2011 - trungdt - Add agregate to Article module
		// Now, we should determine what location_data for this item 
		// because, the client could select the category of other article module
		// not of this module		
		if (isset($_POST['categories'])) {
			$object->category_id = $_POST['categories'];
		}
		else
		  $object->category_id=0;
	   // Sep 12, 2011 - trungdt - End
	   // Sep 13, 2011 - trungdt - summary
	   $object->summary=$values['summary'];
	   $object->dont_show_readmore = empty($values['dont_show_readmore']) ? 0 : 1;
		return $object;
	}
}

?>
